<template>
  <div class="alarmConfiguration zy-content">
    <search
      :columns="searchData"
      @getSearch="getSearch(arguments)"
      key="search"
    ></search>
    <div class="list-layout mt16">
      <!-- 批量删除 批量导出  批量导入 下载模板 新增-->
      <div class="btns clear">
        <span class="title">{{ $t("common.listInformation") }}</span>
        <Button @click="getTableColumns(columns)">
          {{ handleContextMenuStatus ? $t("显示操作栏") : $t("隐藏操作栏") }}
        </Button>
      </div>
      <!-- 表格 -->
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columnsList"
          ellipsis
          ref="selection"
          stripe
          highlight-row
          @on-row-click="rowClick"
          hightlight
          :data="dataArr"
          @on-selection-change="onSelectChange"
        >
          <template slot-scope="{ row }" slot="action">
            <span
              v-has="'labelprint'"
              class="operationBtn"
              @click="showForm(row, 'new')"
              ><i class="iconfont zy-common-bianji"></i>打印</span
            >
          </template>
        </Table>
      </div>
      <!-- 分页 -->
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="pageSizeOption"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
    <!-- 补-------- -->
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">标签明细</span>
      </div>
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columns2"
          ellipsis
          ref="selection"
          stripe
          :data="dataArr2"
        >
          <template slot-scope="{ row }" slot="action">
            <span
              v-has="'labelreprint'"
              class="operationBtn"
              @click="showForm(row, 'edit')"
              ><i class="iconfont zy-common-bianji"></i>补印</span
            >
          </template>
        </Table>
      </div>
      <!-- 分页 -->
      <div class="pageWrap mt16">
        <Page
          :total="total2"
          :page-size="pageSize2"
          :page-size-opts="pageSizeOption"
          :current="pageNum2"
          @on-change="changePageNum2"
          @on-page-size-change="changePageSize2"
          show-sizer
          show-total
        />
      </div>
    </div>
    <!-- 请确认是否删除弹框 -->
    <Modal
      :mask-closable="false"
      v-model="delFaultCodeShowF"
      :title="$t('common.Delete')"
      class="modal-title-layout"
    >
      <div class="icon red">
        <i class="iconfont zy-common-shanchu"></i>
      </div>
      <p class="title">
        <span>{{ $t("common.confirmDelete") }}</span>
      </p>
      <div slot="footer">
        <Button type="default" @click="delFaultCodeShowF = false">{{
          $t("common.Cancle")
        }}</Button>
        <Button type="primary" :loading="loading" @click="deleteOk">{{
          $t("maintenance.Confirmed")
        }}</Button>
      </div>
    </Modal>
    <ledger-print-modal @hasPrint="hasPrint" ref="ledgerPrintModal" />
    <addModel ref="addModel" @print="print"></addModel>
  </div>
</template>

<script>
import toggleTableOperation from "@/mixins/toggleTableOperation";
import search from "@/components/curd/searchList.vue";
import ledgerPrintModal from "./modules/ledgerPrintModal";
import addModel from "./modules/addMode";

export default {
  name: "storeHouse", //仓库配置
  components: { search, ledgerPrintModal, addModel },
  mixins: [toggleTableOperation],
  data() {
    return {
      type: "打印",
      showDetailDialog: false,
      shelfList: [],
      locationList: [],
      importExcelState: false /*批量导入*/,
      formItem: {},
      allCheck: false,
      loading: false,
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,

      pageNum2: 1,
      pageSize2: 10,
      total2: 0,

      searchData: [
        {
          title: "工单号",
          key: "workCode",
        },
        {
          title: "模具编号",
          key: "moldCode",
        },
        {
          title: "产品编号",
          key: "materialCode",
        },
        {
          title: "状态",
          key: "state",
          type: "select",
          dicData: [
            {
              label: "完成",
            },
            {
              label: "下发",
            },
            {
              label: "生产",
            },
            {
              label: "中断",
            },
            {
              label: "暂停",
            },
            {
              label: "转产中",
            },
            {
              label: "转产完成",
            },
            {
              label: "调机中",
            },
            {
              label: "调机完成",
            },
          ],
          params: {
            label: "label",
            value: "label",
          },
        },
        {
          title: "实际开始时间",
          key: "time",
          type: "daterange",
          span: "4",
        },
      ],
      columns: [
        {
          key: "selection",
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          title: "打印数量",
          key: "printQuantity",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "补印数量",
          key: "reprintingQuantity",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "工单号",
          key: "workCode",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "状态",
          key: "state",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "功能位置",
          key: "installPositionName",
          minWidth: 120,
          align: "center",
          resizable: true,
        },
        {
          title: "工序",
          key: "productionProcesses",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "设备编号",
          key: "deviceCode",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "模具名称",
          key: "moldName",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "产品编号",
          key: "materialCode",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "产品名称",
          key: "materialName",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "产品型号",
          key: "materialModel",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "计划生产数量",
          key: "planProduceQuantity",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "完成数量",
          key: "produceQuantity",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "计划开始时间",
          key: "workStartTime",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "计划完成时间",
          key: "workEndTime",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "实际开始时间",
          key: "produceStartTime",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "实际结束时间",
          key: "produceEndTime",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "客户",
          key: "custom",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "批次号",
          key: "batchNumber",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: "装箱规则",
          key: "packingRules",
          minWidth: 100,
          align: "center",
          resizable: true,
        },
        {
          title: `${this.$t("common.operation")}`,
          slot: "action",
          fixed: "right",
          minWidth: 160,
          align: "center",
        },
      ],
      columns2: [
        // {
        //     key: "selection",
        //     type: "selection",
        //     width: 60,
        //     align: "center",
        // },
        {
          title: "序号",
          key: "index",
          type: "index",
          width: 100,
          align: "center",
        },
        {
          title: "标签流水号",
          key: "tagSerialNumber",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "装箱数量",
          key: "packingQuantity",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "余料数量",
          key: "residueNumber",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "打印张数",
          key: "printQuantity",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "打印类型",
          key: "labelType",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "制造日期",
          key: "productionDate",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "班组",
          key: "team",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "班次",
          key: "cla",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "打印时间",
          key: "operatorTime",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: "操作人",
          key: "operator",
          minWidth: 200,
          align: "center",
          resizable: true,
          tooltip: true,
        },
        {
          title: `${this.$t("common.operation")}`,
          slot: "action",
          fixed: "right",
          minWidth: 160,
          align: "center",
        },
      ],
      shiftList: [],

      orgList: [], //功能位置
      dataArr: [],
      dataArr2: [],
      delFaultCodeShowF: false, //是否显示删除弹窗
      pageSizeOption: [10, 20, 30, 40],
      delIds: [],
      delIds2: [],
      selection: [],
      checkBtnPermission: {},
      createByOptions: [],
      rows: {},
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns);
    this.searchList();
    // // 基础数据，字典数据
    // this.getDicData("物料类型", this.dicDataList);
    // this.getUserList();
  },
  methods: {
    getSearch(arg) {
      this.searchParams = JSON.parse(JSON.stringify(arg[0]));
      if (this.searchParams.time && this.searchParams.time.length == 2) {
        this.searchParams.startTime = this.searchParams.time[0];
        this.searchParams.endTime = this.searchParams.time[1];
        delete this.searchParams.time;
      }
      this.pageNum = 1;
      this.searchList();
    },
    rowClick(row) {
      this.rows = row;
      this.searchList2();
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },

    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    changeNum2() {
      this.pageNum2 = 1;
      this.searchList2();
    },
    changePageSize2(pageSize) {
      this.pageSize2 = pageSize;
      this.searchList2();
    },
    hasPrint() {
      let formItem = JSON.parse(JSON.stringify(this.$refs.addModel.formItem));
      delete formItem.itemCodebyList;
      formItem["reportingId"] = formItem.id;
      delete formItem.id;
      formItem.tagSerialNumber =
        this.$refs.ledgerPrintModal.timeValueList.join(",");
      for (let key in formItem) {
        if (formItem[key] == null || formItem[key] == undefined) {
          delete formItem[key];
        }
      }
      this.$refs.ledgerPrintModal.printLoading=true;
      this.axios({
        url:
          this.type == "new"
            ? "/dms/labelPrinting/operationLabelPrinting"
            : "/dms/labelPrinting/updateLabelPrinting",
            // ? "/dms/labelPrinting/addLabelPrinting"
            // : "/dms/labelPrinting/updateLabelPrinting",
        method: "post",
        data: {
          ...formItem,
        },
      }).then((res) => {
          this.$refs.ledgerPrintModal.printLoading = false;
        if (res.code==200) {
          this.$refs.ledgerPrintModal.getPrintDevice();
          this.$refs.ledgerPrintModal.close();

          this.$refs.addModel.close();
          this.searchList();
          this.searchList2();
          
            // if (res.code == 200) {
            //   this.$refs.ledgerPrintModal.close();
            //   this.$refs.addModel.close();
            //   this.searchList();
            //   this.searchList2();
            // } else {
            //   this.$Message.warning(res.msg);
            //   this.$refs.ledgerPrintModal.printLoading = false;
            // }
        }else{
          this.$Message.error(res.msg);
        }
      });
    },
    changePageNum2(val) {
      this.pageNum2 = val;
      this.searchList2();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams,
      };
      this.axios({
        method: "post",
        url: "/dms/labelPrinting/getLabelPrintingList",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    searchList2() {
      let params = {
        pageNum: this.pageNum2,
        pageSize: this.pageSize2,
        workCode: this.rows.workCode,
      };
      this.axios({
        method: "post",
        url: "/dms/labelPrinting/getLabelDetailsList",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr2 = res.data.records;
          this.total2 = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //勾选列表
    onSelectChange(selection) {
      let myArray = [];
      selection.map((item, index) => {
        myArray.push(item.id);
      });
      this.delIds = myArray;
      if (selection.length > 0) {
        this.allCheck = true;
      } else {
        this.allCheck = false;
      }
    },
    showForm(row, type) {
      this.type = type;
      let params = JSON.parse(JSON.stringify(row));
      params.deviceNo = params.deviceCode;
      delete params.deviceCode;
      this.$refs.addModel.show(params, type);
    },
    print(formItem) {
      this.$refs.ledgerPrintModal.show({ ...formItem }, formItem.labelType);
    },
  },
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}
</style>
